import os.path
import time
import HTMLTestRunner_PY3
import yagmail,logging

class Tools():
    def report1(self):
        report = HTMLTestRunner_PY3.HTMLTestRunner(open('movie_py3.html', 'wb'),
                                                   title='维度电影项目测试报告',
                                                   description='内容为购票下单')
        return report

    def Log1(self):
        log = logging.basicConfig(level=logging.DEBUG,
                                  format='%(levelname)s %(asctime)s %(filename)s %(message)s %(lineno)d')
        return log

    def Log2(self):
        log = logging.basicConfig(level=logging.DEBUG,
                                  format='%(levelname)s-%(asctime)s-%(filename)s-%(message)s-%(lineno)d',
                                  filemode='a+',
                                  filename='movie.log')
        return log

    def Log3(self):
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        ch = logging.StreamHandler()
        ch.setLevel(logging.INFO)
        fmt = logging.Formatter('%(levelname)s->%(filename)s->%(asctime)s->%(message)s->%(lineno)d')
        ch.setFormatter(fmt)
        logger.addHandler(ch)

        print('这是一个INFO日志')

    def Log4(self):
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        currTime = time.strftime('%Y-%m-%d')
        log_py_path = os.path.abspath(__file__) # 当前py文件的绝对路径，会定位到当前文件的绝对路径
        log_dir_path = os.path.split(log_py_path)[0] # 当前py文件夹对应的绝对路径
        pro_path = os.path.dirname(log_dir_path) # 当前py文件 对应上一级的目录
        Log_path = pro_path+'./'
        log_name = Log_path + currTime +'.log'
        fh = logging.FileHandler(log_name,mode='a+')
        fh.setLevel(logging.INFO)
        fmt = logging.Formatter('%(asctime)s-%(filename)s:[%(lineno)s]-[%(levelname)s]-%(message)s')
        fh.setFormatter(fmt)
        logger.addHandler(fh)
        logging.info('This is INFO level')


    def send_email(self):
        mail = yagmail.SMTP(user='3047217905@qq.com',password='wsmqyonwzaxqdcgj',host='smtp.qq.com',port='465')
        mail.send(to='3047217905@qq.com',subject='19-刘婷婷-维度系列接口',contents=['WeiDu_DianShang1.py',
                                                                          'WeiDu_DianShang2.py',
                                                                          'WeiDu_Health1.py',
                                                                          'WeiDu_Health2.py',
                                                                          'WeiDu_Keji1.py',
                                                                          'WeiDu_Keji2.py',
                                                                          'WeiDu_Movie1.py',
                                                                          'WeiDu_Movie2.py',
                                                                          'WeiDu_XinWen1.py',
                                                                          'WeiDu_XinWen2.py',
                                                                          'WeiDu_XinWen3.py',
                                                                          'WeiDu_YueChe2.py',
                                                                          'WeiDu_YueChe1.py'])
        mail.close()